package com.hzsai.mininote.common;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import java.util.Locale;

/**
 *
 * @author hzsai
 * @date 2020/1/16
 * */
@Component
public class I18nPool/* implements ApplicationContextAware */{

//    private static ApplicationContext context = null;

//    public static String getWord(String word) {
//        Locale locale = LocaleContextHolder.getLocale();
////        return context.getBean(MessageSource.class).getMessage(word, null, locale);
//    }

    private static MessageSource messageSource = null;

    public I18nPool(MessageSource messageSource) {
        I18nPool.messageSource = messageSource;
    }

    public static String getWord(String word) {

        Locale locale = LocaleContextHolder.getLocale();

        return messageSource.getMessage(word, null, locale);
    }

    /**
     */
//    @Override
//    public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws BeansException {
//        context = applicationContext;
//    }
}
